// ============================================================================
//
// LCP-net framework by Pierre CHATEL chatelp@gmail.com
// Distributed under GPLv3
// Copyright (C) THALES Land & Joint Systems, 2008, 2009. All rights reserved
//
// ============================================================================

/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package com.thalesgroup.preferenceFramework.models.LCPnet.impl;

import java.util.Collection;


import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentWithInverseEList;
import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.EObjectResolvingEList;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.util.InternalEList;

import com.thalesgroup.preferenceFramework.models.LCPnet.CLPT;
import com.thalesgroup.preferenceFramework.models.LCPnet.CLPTLine;
import com.thalesgroup.preferenceFramework.models.LCPnet.LCPnetPackage;
import com.thalesgroup.preferenceFramework.models.LCPnet.LNodeValue;
import com.thalesgroup.preferenceFramework.models.LCPnet.LNodeValueUtility;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>CLPT Line</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link com.thalesgroup.preferenceFramework.models.LCPnet.impl.CLPTLineImpl#getName <em>Name</em>}</li>
 *   <li>{@link com.thalesgroup.preferenceFramework.models.LCPnet.impl.CLPTLineImpl#getTable <em>Table</em>}</li>
 *   <li>{@link com.thalesgroup.preferenceFramework.models.LCPnet.impl.CLPTLineImpl#getParentValues <em>Parent Values</em>}</li>
 *   <li>{@link com.thalesgroup.preferenceFramework.models.LCPnet.impl.CLPTLineImpl#getUtility <em>Utility</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class CLPTLineImpl extends EObjectImpl implements CLPTLine {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getParentValues() <em>Parent Values</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getParentValues()
	 * @generated
	 * @ordered
	 */
	protected EList<LNodeValue> parentValues;

	/**
	 * The cached value of the '{@link #getUtility() <em>Utility</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUtility()
	 * @generated
	 * @ordered
	 */
	protected EList<LNodeValueUtility> utility;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected CLPTLineImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return LCPnetPackage.Literals.CLPT_LINE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, LCPnetPackage.CLPT_LINE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CLPT getTable() {
		if (eContainerFeatureID != LCPnetPackage.CLPT_LINE__TABLE) return null;
		return (CLPT)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetTable(CLPT newTable, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newTable, LCPnetPackage.CLPT_LINE__TABLE, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTable(CLPT newTable) {
		if (newTable != eInternalContainer() || (eContainerFeatureID != LCPnetPackage.CLPT_LINE__TABLE && newTable != null)) {
			if (EcoreUtil.isAncestor(this, newTable))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newTable != null)
				msgs = ((InternalEObject)newTable).eInverseAdd(this, LCPnetPackage.CLPT__LINES, CLPT.class, msgs);
			msgs = basicSetTable(newTable, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, LCPnetPackage.CLPT_LINE__TABLE, newTable, newTable));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<LNodeValue> getParentValues() {
		if (parentValues == null) {
			parentValues = new EObjectResolvingEList<LNodeValue>(LNodeValue.class, this, LCPnetPackage.CLPT_LINE__PARENT_VALUES);
		}
		return parentValues;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<LNodeValueUtility> getUtility() {
		if (utility == null) {
			utility = new EObjectContainmentWithInverseEList<LNodeValueUtility>(LNodeValueUtility.class, this, LCPnetPackage.CLPT_LINE__UTILITY, LCPnetPackage.LNODE_VALUE_UTILITY__LINE);
		}
		return utility;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case LCPnetPackage.CLPT_LINE__TABLE:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetTable((CLPT)otherEnd, msgs);
			case LCPnetPackage.CLPT_LINE__UTILITY:
				return ((InternalEList<InternalEObject>)(InternalEList<?>)getUtility()).basicAdd(otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case LCPnetPackage.CLPT_LINE__TABLE:
				return basicSetTable(null, msgs);
			case LCPnetPackage.CLPT_LINE__UTILITY:
				return ((InternalEList<?>)getUtility()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case LCPnetPackage.CLPT_LINE__TABLE:
				return eInternalContainer().eInverseRemove(this, LCPnetPackage.CLPT__LINES, CLPT.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case LCPnetPackage.CLPT_LINE__NAME:
				return getName();
			case LCPnetPackage.CLPT_LINE__TABLE:
				return getTable();
			case LCPnetPackage.CLPT_LINE__PARENT_VALUES:
				return getParentValues();
			case LCPnetPackage.CLPT_LINE__UTILITY:
				return getUtility();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case LCPnetPackage.CLPT_LINE__NAME:
				setName((String)newValue);
				return;
			case LCPnetPackage.CLPT_LINE__TABLE:
				setTable((CLPT)newValue);
				return;
			case LCPnetPackage.CLPT_LINE__PARENT_VALUES:
				getParentValues().clear();
				getParentValues().addAll((Collection<? extends LNodeValue>)newValue);
				return;
			case LCPnetPackage.CLPT_LINE__UTILITY:
				getUtility().clear();
				getUtility().addAll((Collection<? extends LNodeValueUtility>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case LCPnetPackage.CLPT_LINE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case LCPnetPackage.CLPT_LINE__TABLE:
				setTable((CLPT)null);
				return;
			case LCPnetPackage.CLPT_LINE__PARENT_VALUES:
				getParentValues().clear();
				return;
			case LCPnetPackage.CLPT_LINE__UTILITY:
				getUtility().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case LCPnetPackage.CLPT_LINE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case LCPnetPackage.CLPT_LINE__TABLE:
				return getTable() != null;
			case LCPnetPackage.CLPT_LINE__PARENT_VALUES:
				return parentValues != null && !parentValues.isEmpty();
			case LCPnetPackage.CLPT_LINE__UTILITY:
				return utility != null && !utility.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //CLPTLineImpl
